package com.dao;

import com.entity.KanjiaEntity;
import com.entity.view.KanjiaView;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.math.BigDecimal;

/**
 * 砍价信息
 * 
 * @author 
 * @email 
 * @date 2025-09-11
 */
public interface KanjiaDao extends BaseMapper<KanjiaEntity> {
	
	List<KanjiaView> selectListView(@Param("ew") Wrapper<KanjiaEntity> wrapper);

	List<KanjiaView> selectListView(Pagination page, @Param("ew") Wrapper<KanjiaEntity> wrapper);
	
	KanjiaView selectView(@Param("ew") Wrapper<KanjiaEntity> wrapper);
	
	/**
	 * 根据商品分类获取成交均价（近3笔同款）
	 */
	@Select("SELECT AVG(o.price) as avgPrice FROM orders o " +
			"JOIN ershoushangpin e ON o.goodid = e.id " +
			"WHERE e.shangpinmingcheng LIKE CONCAT('%', #{shangpinmingcheng}, '%') " +
			"AND e.wupinfenlei = #{wupinfenlei} " +
			"AND o.status IN ('已支付', '已发货', '已完成') " +
			"ORDER BY o.addtime DESC " +
			"LIMIT 3")
	BigDecimal getAvgPriceByCategory(@Param("shangpinmingcheng") String shangpinmingcheng, 
	                               @Param("wupinfenlei") String wupinfenlei);
} 